﻿AB.namespace("AB_Account.Mgr");
AB_Account.Mgr = {
    commandHandler: function (command, record) {
        var FId = record.data.FId;
        switch (command) {
            case "Edit":
                FIdH.setValue(FId);
                AccountEidtStore.load();
                break;
            case "Delete":
                Ext.Msg.confirm('提示', '确定要删除该记录吗?', function (btn) {
                    if (btn == "yes") {
                        Ext.Ajax.request({
                            url: "/Account/DeleteAccount",
                            method: 'post',
                            params: {
                                FId: FId
                            },
                            success: function (result) {
                                if (!isTimeOut(result)) {
                                    var response = Ext.util.JSON.decode(result.responseText);
                                    if (response.success == false) {
                                        ajaxFailureHandler(response);
                                    } else {
                                        FIdH.setValue("");
                                        EditFormPanel.form.reset();

                                        var mark = RoleStore.data.items;
                                        FRoleId.setValue(mark[0].data.FId);

                                        var mark2 = StatusStore.data.items;
                                        FStatusId.setValue(mark2[0].data.FID);

                                        AccountListStore.reload();
                                    }
                                }
                            },
                            failure: failureHandler
                        });
                    }
                });
                break;
        }
    },
    successHandler: function (form, action) {
        if (!isTimeOut(action.response)) {
            AccountListStore.reload();
            alert("账号保存成功。");
        }
        //successHandler(form, action, this.successCallback);
    },
    failureHandler: function (form, action, failureCallback) {
        failureHandler(form, action);
    },
    successCallback: function () {
    },
    failureCallback: function () {
    },
    formStoreLoaded: function (store, records) {
        var formObj = Ext.getCmp("EditFormPanel");
        formStoreLoaded(store, records, formObj);
        RoleStore.load();
        StatusStore.load();
    },
    searchList: function () {
        AccountListStore.reload();
    },
    resetEditData: function () {
        FIdH.setValue("");
        EditFormPanel.form.reset();

        var mark = RoleStore.data.items;
        FRoleId.setValue(mark[0].data.FId);

        var mark2 = StatusStore.data.items;
        FStatusId.setValue(mark2[0].data.FID);
    },
    resetSearchData: function () {
        SearchFormPanel.form.reset();
    },
    deleteAccount: function () {
        var FIdT = FIdH.getValue();
        if (FIdT == "") {
            return;
        }

        Ext.Msg.confirm('提示', '确定要删除该记录吗?', function (btn) {
            if (btn == "yes") {
                Ext.Ajax.request({
                    url: "/Account/DeleteAccount",
                    method: 'post',
                    params: {
                        FId: FIdT
                    },
                    success: function (result) {
                        if (!isTimeOut(result)) {
                            var response = Ext.util.JSON.decode(result.responseText);
                            if (response.success == false) {
                                ajaxFailureHandler(response);
                            } else {
                                FIdH.setValue("");
                                EditFormPanel.form.reset();

                                var mark = RoleStore.data.items;
                                FRoleId.setValue(mark[0].data.FId);

                                var mark2 = StatusStore.data.items;
                                FStatusId.setValue(mark2[0].data.FID);

                                AccountListStore.reload();
                            }
                        }
                    },
                    failure: failureHandler
                });
            }
        });
    }
}

